class Solution(object):
    def executeInstructions(self, n, startPos, s):
        m = len(s)
        ans = [0] * m
        for i in range(m):
            index = i
            now = startPos.copy()
            while index < m:
                if s[index] == 'L':
                    now = [now[0], now[1] - 1]
                if s[index] == 'R':
                    now = [now[0], now[1] + 1]
                if s[index] == 'U':
                    now = [now[0] - 1, now[1]]
                if s[index] == 'D':
                    now = [now[0] + 1, now[1]]
                if 0 <= now[0] < n and 0 <= now[1] < n:
                    index += 1
                else:
                    break
            ans[i] = index - i
        return ans

data = Solution()
n = 3
startPos = [0,1]
s = "RRDDLU"
print(data.executeInstructions(n, startPos, s))